#define AE_USEMEMORYMANAGER
#define AE_OPENGL

#include <AEEngine.h>
#include "fileSystem.h"

#define START_TEST(x) nOK += x()
#define START_TIME	g_dwStart = timeGetTime();
#define END_TIME	-g_dwStart += timeGetTime();
#define TEST_FILE	"coreTest.log"

DWORD g_dwStart, g_dwEnd;

void TestFileSystemHeader()
{
	printf("==========================================================\n");
	printf("= START TESTING AEFileSystem                             =\n");
	printf("==========================================================\n");
}

void TestFileSystemFooter()
{
	printf("==========================================================\n");
	printf("= END TESTING AEFileSystem                               =\n");
	printf("==========================================================\n");
}

int TestOpenValidFile()
{
	printf("= TestOpenValidFile( %s ):\t", TEST_FILE );

	AEFileSystem *fs = &(AEFileSystem::getInstance());

	if( fs == NULL )
	{
		printf("KO - AEFileSystem is NULL\n");
		return 0;
	}

	AERefNew<AEStreamReader> read = fs->OpenReader( TEST_FILE );

	char testbuf[4096];

	AEStreamReader *lpReader = read.GetOwnership();
	lpReader->Read( &testbuf, 4096 );

	lpReader->RemoveReference();
	//lpReader->Read( &testbuf, 4096 );
	printf("OK\n");
	return 1;
}











extern int initFileSystem();

void TestAEFileSystem( DWORD dwTestsMask )
{
	int nOK=0;

	AEStackAllocator test(32000);
	AEMemoryManager::GetInstance().SetHeapAllocator( &test );

	initFileSystem();

	TestFileSystemHeader();
	
	START_TEST(TestOpenValidFile);

	TestFileSystemFooter();
}